﻿using System;
using System.Web;
using System.Net.Mail;
using CE.Company;

/// <summary>
/// Summary description for MailManager
/// </summary>
/// 
namespace CE.Mail
{
    public class MyMailManager
    {
        #region Private Variable
        private MailMessage mail = null;
        private MailAddress mailAddress = null;
        private SmtpClient mailClient = null;
        private int clientPort = -1;
        private string clientHost = String.Empty;
        private bool isEnabledSsl = false;
        private int mailType = -1;
        private string mailBody = "";
        private MailPriority mailPriority = MailPriority.Normal;

        //static string smtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMTPHostName");
        //static string smtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMTPPort");
        //static string smtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMTPAccount");
        //static string smtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMTPDisplayName");
        //static string smtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMTPReplyTo");
        //static string smtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMTPAuthCode");
        //static bool smtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMTPSslEnable"));
        static string smtphost = string.Empty;
        static string smtpport = string.Empty;
        static string smtpaccount = string.Empty;
        static string smtpdisplayname = string.Empty;
        static string smtpreplyto = string.Empty;
        static string smtpauthcode = string.Empty;
        static bool smtpenablessl = true;

        #endregion

        public MyMailManager()
        {
            mailClient = new SmtpClient();
            mailClient.Host = "smtp.gmail.com";
            mailClient.Port = 587;
            mailClient.EnableSsl = true;
        }

        public MyMailManager(string HostName, string Port, bool EnableSSL, string Account, string AuthCode)
        {
            smtphost = HostName;
            smtpenablessl = EnableSSL;
            smtpport = Port;
            smtpaccount = Account;
            smtpauthcode = AuthCode;
        }

        public static bool SendEtiqaEmailByAttachedmentNew(string customername, string email, string emailcc, string emailbcc, string subject, string emailBody, string[] fileList)
        {
            string etiqasmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.EtiqaSMTPHostName");
            string etiqasmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.EtiqaSMTPPort");
            string etiqasmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.EtiqaSMTPAccount");
            string etiqasmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.EtiqaSMTPAuthCode");
            bool etiqasmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.EtiqaSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(etiqasmtphost,
                        Convert.ToInt32(etiqasmtpport),
                        etiqasmtpaccount,
                        etiqasmtpauthcode,
                        subject,
                        etiqasmtpaccount,
                        customername,
                        email,
                        emailcc,
                        emailbcc,
                        subject,
                        emailBody,
                        etiqasmtpenablessl,
                        fileList);
            return _result;
        }

        public static bool SendProposalCompleteNotification(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo)
        {

            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Dear " + PName + ",<br><br>";
            mailBody += "<br>You have just received a completed " + InsType + " (Reference No : " + RefNo + ")";
            mailBody += " online form via <a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a>, dated ";
            mailBody += Date + " timed " + Time + ".";
            mailBody += "<br><br><b>Download Application Form Instruction</b>";
            mailBody += "<br><br>1) Please click on the following link to download the proposal form: ";
            mailBody += "<a href='" + confirmUrl + "'>Click Here</a>.";
            mailBody += "<br>2) Enter your user ID and password to securely download the completed form details.";
            mailBody += "<br><br><br>If you have further queries, please contact us at:<br/>";
            mailBody += _companyAddress;
            mailBody += "<br/>Email: " + _emailaddress;
            //mailBody += "<br><br>CompareXpress Pte Ltd";
            //mailBody += "<br>Blk 750B Chai Chee Road";
            //mailBody += "<br>#04-05 to 08 Technopark@Chai Chee";
            //mailBody += "<br>Singapore 469002";
            //mailBody += "<br>Tel: 6309 1688";
            //mailBody += "<br>Email: support@comparexpress.com";
            mailBody += "<br><br><br>Best regards,";
            mailBody += "<br><br><img src='" + imgUrl + "' width='130' />";
            mailBody += "<br><b><a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> Team</b>";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPDisplayName");
            string cxformssmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPReplyTo");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));

            bool _result = SendMailNew(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        cxformssmtpdisplayname, //"<CX> Email Confirmation to Participating Merchant",
                        cxformssmtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        cxformssmtpreplyto,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from www.gluaygluay.Com",
                        mailBody,
                        cxformssmtpenablessl);
            return _result;
        }

        public static bool SendProposalCompleteNotificationWithAttachment(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;
            //if (myUri.Port != 80 || myUri.Port != 0)
            //{
            //    confirmUrl += ":" + myUri.Port + ConfirmPath;
            //    imgUrl += ":" + myUri.Port;
            //}
            //else
            //{
            confirmUrl += ConfirmPath;
            //}

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Dear " + PName + ",<br><br>";
            mailBody += "<br>You have just received a completed " + InsType + " (Reference No : " + RefNo + ")";
            mailBody += " online form via <a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a>, dated ";
            mailBody += Date + " timed " + Time + ".";
            mailBody += "<br><br><b>Download Application Form Instruction</b>";
            mailBody += "<br><br>1) Please click on the following link to download the proposal form: ";
            mailBody += "<a href='" + confirmUrl + "'>Click Here</a>.";
            mailBody += "<br>2) Enter your user ID and password to securely download the completed form details.";
            mailBody += "<br><br><br>If you have further queries, please contact us at:<br/>";
            mailBody += _companyAddress;
            mailBody += "<br/>Email: " + _emailaddress;
            //mailBody += "<br><br>CompareXpress Pte Ltd";
            //mailBody += "<br>Blk 750B Chai Chee Road";
            //mailBody += "<br>#04-05 to 08 Technopark@Chai Chee";
            //mailBody += "<br>Singapore 469002";
            //mailBody += "<br>Tel: 6309 1688";
            //mailBody += "<br>Email: support@comparexpress.com";
            mailBody += "<br><br><br>Best regards,";
            mailBody += "<br><br><img src='" + imgUrl + "' width='130' />";
            mailBody += "<br><b><a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> Team</b>";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        "<GG> Email Confirmation to Participating Merchant",
                        smtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from www.gluaygluay.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
        }

        public static bool SendCarLMGProposalToUserWithAttachment(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Proposal Reference: " + RefNo + "<br><br>";
            mailBody += "Thank you. Your completed proposal form is submitted to LMG Insurance.<br><br>";
            mailBody += "Liberty will email you the confirmation within 1 working day.<br><br>";
            mailBody += "If you have queries, you may contact 6221 8611 or email <a href='mailto:motorquotation@libertyinsurance.com.sg'>motorquotation@libertyinsurance.com.sg</a>.<br><br>";
            mailBody += "<br>Best Regards,<br/><br>";
            mailBody += "Your <a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> Team<br/>";
            mailBody += "Customer Support - SG/International<br/>";
            mailBody += "<br><br><img src='" + imgUrl + "' width='130' /><br>";
            mailBody += "<hr align='left' width='410px' /><br>";
            mailBody += "<b>CompareXpress Pte Ltd</b><br>";
            mailBody += "750D Chai Chee Road :: #04-06 :: Technopark @ Chai Chee :: Singapore 469004";
            mailBody += "<br/><a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> :: <a href='mailto:support@gluaygluay.com'>support@gluaygluay.com</a>";
            mailBody += "<hr align='left' width='410px'  /><br>";
            mailBody += "<i>This is a computer-generated email. Please do not reply to this email.</i> ";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        "<GG> Email Confirmation to Participating Customer",
                        cxformssmtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from www.gluaygluay.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
        }

        public static bool SendCarAZCpProposalToUserWithAttachment(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Proposal Reference: " + RefNo + "<br><br>";
            mailBody += "Thank you. Your completed proposal form is submitted to AZCp Insurance.<br><br>";
            mailBody += "AZcp will email you the confirmation within 1 working day.<br><br>";
            mailBody += "If you have queries, you may contact 6221 8611 or email <a href='mailto:motorquotation@libertyinsurance.com.sg'>motorquotation@libertyinsurance.com.sg</a>.<br><br>";
            mailBody += "<br>Best Regards,<br/><br>";
            mailBody += "Your <a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> Team<br/>";
            mailBody += "Customer Support - SG/International<br/>";
            mailBody += "<br><br><img src='" + imgUrl + "' width='130' /><br>";
            mailBody += "<hr align='left' width='410px' /><br>";
            mailBody += "<b>CompareXpress Pte Ltd</b><br>";
            mailBody += "750D Chai Chee Road :: #04-06 :: Technopark @ Chai Chee :: Singapore 469004";
            mailBody += "<br/><a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> :: <a href='mailto:support@gluaygluay.com'>support@gluaygluay.com</a>";
            mailBody += "<hr align='left' width='410px'  /><br>";
            mailBody += "<i>This is a computer-generated email. Please do not reply to this email.</i> ";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        "<GG> Email Confirmation to Participating Customer",
                        cxformssmtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from www.gluaygluay.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
        }

        public static bool SendCarMSIGProposalToUserWithAttachment(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Proposal Reference: " + RefNo + "<br><br>";
            mailBody += "Thank you. Your completed proposal form is submitted to MSIG Insurance.<br><br>";
            mailBody += "MSIG will email you the confirmation within 1 working day.<br><br>";
            mailBody += "If you have queries, you may contact 6221 8611 or email <a href='mailto:motorquotation@msig.com.sg'>motorquotation@msig.com.sg</a>.<br><br>";
            mailBody += "<br>Best Regards,<br/><br>";
            mailBody += "Your <a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> Team<br/>";
            mailBody += "Customer Support - TH/International<br/>";
            mailBody += "<br><br><img src='" + imgUrl + "' width='130' /><br>";
            mailBody += "<hr align='left' width='410px' /><br>";
            mailBody += "<b>CompareXpress Pte Ltd</b><br>";
            mailBody += "750D Chai Chee Road :: #04-06 :: Technopark @ Chai Chee :: Singapore 469004";
            mailBody += "<br/><a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> :: <a href='mailto:support@gluaygluay.com'>support@gluaygluay.com</a>";
            mailBody += "<hr align='left' width='410px'  /><br>";
            mailBody += "<i>This is a computer-generated email. Please do not reply to this email.</i> ";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        "<GG> Email Confirmation to Participating Customer",
                        cxformssmtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from www.gluaygluay.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
        }

        public static bool SendCarBKIProposalToUserWithAttachment(string PName, string EmailAddress, string CCEmail, string BCCEmail, string InsType, string Date, string Time, string RefNo, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Proposal Reference: " + RefNo + "<br><br>";
            mailBody += "Thank you. Your completed proposal form is submitted to Bangkok Insurance.<br><br>";
            mailBody += "BKI will email you the confirmation within 1 working day.<br><br>";
            mailBody += "If you have queries, you may contact 6221 8611 or email <a href='mailto:motorquotation@BKI.com.sg'>motorquotation@BKI.com.sg</a>.<br><br>";
            mailBody += "<br>Best Regards,<br/><br>";
            mailBody += "Your <a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> Team<br/>";
            mailBody += "Customer Support - TH/International<br/>";
            mailBody += "<br><br><img src='" + imgUrl + "' width='130' /><br>";
            mailBody += "<hr align='left' width='410px' /><br>";
            mailBody += "<b>CompareXpress Pte Ltd</b><br>";
            mailBody += "750D Chai Chee Road :: #04-06 :: Technopark @ Chai Chee :: Singapore 469004";
            mailBody += "<br/><a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> :: <a href='mailto:support@gluaygluay.com'>support@gluaygluay.com</a>";
            mailBody += "<hr align='left' width='410px'  /><br>";
            mailBody += "<i>This is a computer-generated email. Please do not reply to this email.</i> ";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        "<GG> Email Confirmation to Participating Customer",
                        cxformssmtpaccount,
                        PName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        InsType + " Proposal form (Reference No : " + RefNo + ") - from www.gluaygluay.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
        }

        public static bool SendCarProposalAttachment(string PName, string ToEmailAddress, string CCEMailAddress, string BCCEMailAddress, string InsType, string Date, string Time, string RefNo, string ProviderCompany, string[] fileList)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;
            //if (myUri.Port != 80 || myUri.Port != 0)
            //{
            //    confirmUrl += ":" + myUri.Port + ConfirmPath;
            //    imgUrl += ":" + myUri.Port;
            //}
            //else
            //{
            //    confirmUrl += ConfirmPath;
            //}

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Dear " + PName + ",<br><br>";
            mailBody += "<br>You have just received a completed " + InsType + " (Reference No : " + RefNo + ")";
            mailBody += " online form via <a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a>, dated ";
            mailBody += Date + " timed " + Time + ".";
            mailBody += "<br><br><b>Check Car Insurance related documents of " + ProviderCompany + " Insurance as attachments.</b>";
            mailBody += "<br><br><br>If you have further queries, please contact us at:";
            mailBody += _companyAddress;
            mailBody += "<br/>Email: " + _emailaddress;
            //mailBody += "<br><br>CompareXpress Pte Ltd";
            //mailBody += "<br>Blk 750B Chai Chee Road";
            //mailBody += "<br>#04-05 to 08 Technopark@Chai Chee";
            //mailBody += "<br>Singapore 469002";
            //mailBody += "<br>Tel: 6309 1688";
            //mailBody += "<br>Email: support@comparexpress.com";
            mailBody += "<br><br><br>Best regards,";
            mailBody += "<br><br><img src='" + imgUrl + "' width='130' />";
            mailBody += "<br><b><a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> Team</b>";

            string cxformssmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPHostName");
            string cxformssmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPPort");
            string cxformssmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAccount");
            string cxformssmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPAuthCode");
            bool cxformssmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFormsSMTPSslEnable"));

            bool _result = SendMailNewByAttachments(cxformssmtphost,
                        Convert.ToInt32(cxformssmtpport),
                        cxformssmtpaccount,
                        cxformssmtpauthcode,
                        "<CX> Attach documents for Car Insurance realted documents",
                        cxformssmtpaccount,
                        PName,
                        ToEmailAddress,
                        CCEMailAddress,
                        BCCEMailAddress,
                        InsType + "Car Insurance Related Documents (Reference No : " + RefNo + ") - from www.gluaygluay.Com",
                        mailBody,
                        cxformssmtpenablessl, fileList);
            return _result;
            //return true;
        }

        //public static bool SendPasswordResetLink(string UserName, string EmailAddress, string AuthSalt, string UniquiId, CE.Global.CEUserType UserType)
        //{
        //    Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

        //    string domainUrl = "";
        //    string ConfirmPath = "";
        //    string userType = "";
        //    if (UserType == CE.Global.CEUserType.Customer)
        //    {
        //        domainUrl = "http://" + myUri.Host;
        //        userType = "Customer";
        //        ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ResetCustomerPasswordPath");
        //    }
        //    else if (UserType == CE.Global.CEUserType.Provider)
        //    {
        //        domainUrl = "https://" + myUri.Host;
        //        userType = "Provider";
        //        ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ResetProviderPasswordPath");
        //    }

        //    string confirmUrl = domainUrl;
        //    string imgUrl = domainUrl;
        //    confirmUrl += ConfirmPath;

        //    imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");

        //    string mailBody = "<img src='" + imgUrl + "' width='130' /><br>" + Resources.WelcomeEmail.YourAccount + " : <b>" + UserName + "</b><br>";
        //    mailBody += "<br><a href='" + confirmUrl + "?authkey=" + AuthSalt + "&uid=" + UniquiId + "'>" + Resources.WelcomeEmail.ClickHere + "</a> " + Resources.WelcomeEmail.ResetAccountPassword;
        //    mailBody += "<br><br><br>" + Resources.WelcomeEmail.Thankyou;
        //    mailBody += "<br>" + Resources.WelcomeEmail.BestRegards + ",";
        //    mailBody += "<br>" + Resources.WelcomeEmail.CompareXpressMembership;

        //    string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPHostName");
        //    string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPPort");
        //    string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAccount");
        //    string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPDisplayName");
        //    string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPReplyTo");
        //    string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAuthCode");
        //    bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPSslEnable"));

        //    string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.Feedback_CC"].ToString();
        //    string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.Feedback_BCC"].ToString();

        //    bool _result = SendMailNew(noreplysmtphost,
        //                Convert.ToInt32(noreplysmtpport),
        //                noreplysmtpaccount,
        //                noreplysmtpauthcode,
        //                noreplysmtpdisplayname, //"กล้วยๆ.com Membership Service",
        //                noreplysmtpaccount,
        //                userType,
        //                EmailAddress,
        //                _emailCC,
        //                _emailBCC,
        //                noreplysmtpreplyto,
        //                "Password Recovery - www.gluaygluay.Com",
        //                mailBody,
        //                noreplysmtpenablessl);
        //    return _result;
        //}

        public static bool SendNotification(string EmailAddress, string EmailSubject, string EmailMessage)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPSslEnable"));

            string _emailCC = ""; //System.Configuration.ConfigurationSettings.AppSettings["Mobile.CRM_CC"].ToString();
            string _emailBCC = ""; //System.Configuration.ConfigurationSettings.AppSettings["Mobile.CRM_BCC"].ToString();

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname, //"กล้วยๆ.com",
                        noreplysmtpaccount,
                        "Member",
                        EmailAddress,
                        _emailCC,
                        _emailBCC,
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl);
            return _result;
        }

        public static bool SendCRMMessage(string EmailAddress, string EmailSubject, string EmailMessage)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPSslEnable"));

            string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.CRM_CC"].ToString();
            string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.CRM_BCC"].ToString();

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname, //"กล้วยๆ.com",
                        noreplysmtpaccount,
                        "Member",
                        EmailAddress,
                        _emailCC,
                        _emailBCC,
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl);
            return _result;
        }

        public static bool SendSelectedCARMessage(string EmailAddress, string EmailSubject, string EmailMessage)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPSslEnable"));

            string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.CI_APP_CC"].ToString();
            string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.CI_BCC"].ToString();

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname, //"กล้วยๆ.com",
                        noreplysmtpaccount,
                        "Member",
                        EmailAddress,
                        _emailCC,
                        _emailBCC,
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl);
            return _result;
        }

        public static bool SendSelectedCARMessageToAgent(string EmailAddress, string CCEmail, string BCCEmail, string EmailSubject, string EmailMessage)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPSslEnable"));


            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname, //"กล้วยๆ.com",
                        noreplysmtpaccount,
                        "Member",
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl);
            return _result;
        }
        
        public static bool SendFeedBack(string SenderEmailAddress, string EmailAddress, string EmailSubject, string EmailMessage)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string imgUrl = domainUrl;
            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");
            string mailBody = "<img src='" + imgUrl + "' width='130' alt='กล้วยๆ.com'/><br>";
            mailBody += EmailMessage;

            mailBody += "<br><br><br>Thank you very much!";
            mailBody += "<br>Regards,";
            mailBody += "<br><b>Feedback Mail Service</b>";
            mailBody += "<br><b><a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a></b><br>";


            string cxfeedbacksmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFeedBackSMTPHostName");
            string cxfeedbacksmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFeedBackSMTPPort");
            string cxfeedbacksmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFeedBackSMTPAccount");
            string cxfeedbacksmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFeedBackSMTPDisplayName");
            string cxfeedbacksmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFeedBackSMTPReplyTo");
            string cxfeedbacksmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFeedBackSMTPAuthCode");
            bool cxfeedbacksmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXFeedBackSMTPSslEnable"));

            string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.Feedback_CC"].ToString();
            string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.Feedback_BCC"].ToString();

            bool _result = SendMailNew(cxfeedbacksmtphost,
                        Convert.ToInt32(cxfeedbacksmtpport),
                        cxfeedbacksmtpaccount,
                        cxfeedbacksmtpauthcode,
                        cxfeedbacksmtpdisplayname, //"กล้วยๆ.com",
                        cxfeedbacksmtpaccount,
                        "Mail Service",
                        EmailAddress,
                        _emailCC,
                        _emailBCC,
                        cxfeedbacksmtpreplyto,
                        EmailSubject,
                        mailBody,
                        cxfeedbacksmtpenablessl);

            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPSslEnable"));

            SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname, //"กล้วยๆ.com",
                        noreplysmtpaccount,
                        "Mail Service",
                        SenderEmailAddress,
                        _emailCC,
                        _emailBCC,
                        noreplysmtpreplyto,
                        "Thank you for your feedback - www.gluaygluay.com",
                        "Dear Feedback Sender,<br/><br/> Thank you very much for your feedback. <br/><br/> Your Message :" + EmailMessage + " <br /><br />Regards, <br/><img src='" + imgUrl + "' width='130' alt='www.gluaygluay.com'/><br><b><a href='http://www.gluaygluay.com' target=_blank'>www.gluaygluay.com</a> Team</b>",
                        noreplysmtpenablessl);
            return _result;
        }

        public static bool SendMailNew(string sHost, int nPort, string sUserName, string sPassword, string sFromName, string sFromEmail,
        string sToName, string sToEmail, string sCCEmail, string sBCCEmail, string sReplyToEmail, string sHeader, string sMessage, bool fSSL)
        {
            if (sToName.Length == 0)
                sToName = sToEmail;
            if (sFromName.Length == 0)
                sFromName = sFromEmail;

            try
            {
                MailMessage Mail = new MailMessage();

                if (sToEmail != "")
                {
                    string[] sGetToEmails = sToEmail.Split(';');

                    foreach (string toemail in sGetToEmails)
                    {
                        if (toemail != "")
                            Mail.To.Add(new MailAddress(toemail));
                    }
                }

                if (sCCEmail != "")
                {
                    string[] sGetCCEmails = sCCEmail.Split(';');

                    foreach (string ccemail in sGetCCEmails)
                    {
                        if (ccemail != "")
                            Mail.CC.Add(new MailAddress(ccemail));
                    }
                }

                if (sBCCEmail != "")
                {
                    string[] sGetBCCEmails = sBCCEmail.Split(';');

                    foreach (string bccemail in sGetBCCEmails)
                    {
                        if (bccemail != "")
                            Mail.Bcc.Add(new MailAddress(bccemail));
                    }

                }

                Mail.From = new MailAddress(sFromEmail, sFromName); ;
                Mail.Subject = sHeader;
                Mail.Body = sMessage;
                Mail.IsBodyHtml = true;
                Mail.ReplyTo = new MailAddress(sReplyToEmail);               

                SmtpClient smtp = new SmtpClient();
                smtp.Port = nPort;
                smtp.Host = sHost;
                smtp.Credentials = new System.Net.NetworkCredential(sUserName, sPassword);

                if (fSSL)
                {
                    smtp.EnableSsl = true;
                }

                smtp.SendCompleted += new SendCompletedEventHandler(MailDeliveryComplete);
                smtp.Send(Mail);


            }
            catch (Exception Ex)
            {
                string _emailSetting = "Host : " + sHost + " From Email : " + sUserName + " To Email : " + sToEmail + " Subject : " + sHeader;
                CreateExceptionLog(Ex, _emailSetting, "SendMailNew Exception");
                return false;
            }
            finally
            {
                string MailCountStart = CE.Configuration.MyConfigurationManager.GetAppSettingValue("MailCountStart");
                if (MailCountStart == "1")
                {
                    MailCountLog mcl = new MailCountLog();
                    mcl.InsertMailCountLog("GG Mobile");
                }
            }

            return true;
        }

        static void MailDeliveryComplete(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {

            if (e.Error != null)
            {
                try
                {
                    //Get the Original MailMessage object
                    MailMessage mail = (MailMessage)e.UserState;

                    //write out the subject
                    string subject = mail.Subject;

                    System.Text.StringBuilder errorMsg = new System.Text.StringBuilder();
                    errorMsg.Append(string.Format("An error occurred sending message [{0}]. {1}", e.UserState.ToString(), e.Error.Message));

                    if (e.Error.InnerException != null)
                        errorMsg.Append(Environment.NewLine + "Inner exception message: " + e.Error.InnerException.Message);

                    errorMsg.Append(Environment.NewLine + "Subject: " + subject);
                    errorMsg.Append(Environment.NewLine + "Sender: " + mail.Sender.Address.ToString());
                    errorMsg.Append(Environment.NewLine + "Sender Host: " + mail.Sender.Host.ToString());
                    errorMsg.Append(Environment.NewLine + "From : " + mail.From.Address.ToString());
                    errorMsg.Append(Environment.NewLine + "From Host : " + mail.From.Host.ToString());
                    string _toAddresses = "";
                    foreach (MailAddress _msgMail in mail.To)
                    {
                        _toAddresses += _msgMail.Address.ToString() + ";";
                    }
                    errorMsg.Append(Environment.NewLine + "To : " + _toAddresses);
                    CreateMailDeliveryExceptionLog("SendMailNew MailDeliveryComplete Exception", errorMsg);
                }
                catch (Exception Ex)
                {
                    Ex = null;
                }
            }
            else if (e.Cancelled)
            {
            }
            else
            {
                //Console.WriteLine("Message sent.");
            }
        }

        public static bool SendMailNewByAttachments(string sHost, int nPort, string sUserName, string sPassword, string sFromName, string sFromEmail,
        string sToName, string sToEmail, string sToCCEmail, string sToBCCEmail, string sHeader, string sMessage, bool fSSL, string[] fileList)
        {
            bool _retValue = false;
            try
            {
                if (sToName.Length == 0)
                    sToName = sToEmail;
                if (sFromName.Length == 0)
                    sFromName = sFromEmail;

                System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage();
                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = sHost;
                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;

                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = nPort.ToString();
                if (fSSL)
                    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true";

                if (sUserName.Length == 0)
                {
                    //Ingen auth 
                }
                else
                {
                    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
                    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sUserName;
                    Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sPassword;
                }

                Mail.To = sToEmail;
                Mail.From = sFromEmail;
                Mail.Subject = sHeader;
                Mail.Body = sMessage;
                Mail.Cc = sToCCEmail;
                Mail.Bcc = sToBCCEmail;

                for (int i = 0; i < fileList.Length; i++)
                {
                    Mail.Attachments.Add(new System.Web.Mail.MailAttachment(fileList[i].ToString()));
                }

                Mail.BodyFormat = System.Web.Mail.MailFormat.Html;

                System.Web.Mail.SmtpMail.SmtpServer = sHost;
                System.Web.Mail.SmtpMail.Send(Mail);
                _retValue = true;
            }
            catch (Exception Ex)
            {
                string _emailSetting = "Host : " + sHost + " From Email : " + sUserName + " To Email : " + sToEmail + " Subject : " + sHeader;
                CreateExceptionLog(Ex, _emailSetting, "SendMailNew By Attachments Exception");
                _retValue = false;
            }

            return _retValue;
        }

        public static bool SendProviderNotificationUpdates(string ToEmailAddress, string CCEmailAddress, string BCCEmailAddress, string EmailSubject, string ProviderName,
            string UserId, string ModuleName, int TransType, string OtherInfo)
        {

            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "http://" + myUri.Host;
            string ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ProviderPath");

            string confirmUrl = domainUrl;
            string imgUrl = domainUrl;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.LogoPath");

            string Transaction = "";

            if (TransType == 1)
            {
                Transaction = "Insert";
            }
            else if (TransType == 2)
            {
                Transaction = "Update";
            }
            else
            {
                Transaction = "Delete";
            }

            CompanyInformation _company = new CompanyInformation();
            CompanyInformationDB _companydb = new CompanyInformationDB();
            _company = _companydb.GetCompanyInformation(1);
            string _companyAddress = "";
            string _emailaddress = "";
            if (_company != null)
            {
                _companyAddress = _company.Address1;
                _emailaddress = _company.EmailAddress;
            }
            _company = null;
            _companydb = null;

            string mailBody = "<br>Dear " + ProviderName + " Insurance,<br><br>";
            mailBody += "<br>You have just updated your " + ModuleName + " Page.";
            mailBody += "<br><br>Transaction Type: " + Transaction;
            mailBody += "<br>" + OtherInfo;
            mailBody += "<br>Date: " + Global.General.GetUTCDateTime().ToString();
            mailBody += "<br>UserID: " + UserId;
            mailBody += "<br><br><br>If you have further queries, please contact us at:<br/>";
            mailBody += _companyAddress;
            mailBody += "<br/>Email: " + _emailaddress;
            mailBody += "<br><br><br>Best regards,";
            mailBody += "<br><br><img src='" + imgUrl + "' width='130' />";
            mailBody += "<br><b><a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> Team</b>";

            bool _result = SendMailNew(smtphost,
                        Convert.ToInt32(smtpport),
                        smtpaccount,
                        smtpauthcode, 
                        smtpdisplayname, //"กล้วยๆ.com",
                        smtpaccount,
                        "Member",
                        ToEmailAddress,
                        CCEmailAddress,
                        BCCEmailAddress,
                        smtpreplyto,
                        EmailSubject,
                        mailBody,
                        smtpenablessl);
            return _result;
        }

        public static bool SendErrorMessage(string TitlePrefix, string EmailMessage)
        {
            string _errormessagereceiver = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.ErrorMessageReceiver");

            string cxerrorsmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXErrorSMTPHostName");
            string cxerrorsmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXErrorSMTPPort");
            string cxerrorsmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXErrorSMTPAccount");
            string cxerrorsmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXErrorSMTPDisplayName");
            string cxerrorsmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXErrorSMTPReplyTo");
            string cxerrorsmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXErrorSMTPAuthCode");
            bool cxerrorsmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXErrorSMTPSslEnable"));

            bool _result = SendMailNew(cxerrorsmtphost,
                        Convert.ToInt32(cxerrorsmtpport),
                        cxerrorsmtpaccount,
                        cxerrorsmtpauthcode,
                        cxerrorsmtpdisplayname, //"กล้วยๆ.com",
                        cxerrorsmtpaccount,
                        TitlePrefix + " CX Error Message Service",
                        _errormessagereceiver,
                        "",
                        "",
                        cxerrorsmtpreplyto,
                        TitlePrefix + " Error - " + Global.General.GetUTCDateTime().ToString(),
                        EmailMessage,
                        cxerrorsmtpenablessl);

            return _result;
        }

        private static void CreateExceptionLog(Exception Ex, string EmailSettingInfo, string strLocation)
        {
            String[] _fileContent = new String[7];
            _fileContent[0] = "Email Setting : " + EmailSettingInfo;
            _fileContent[1] = "Source : " + Ex.Source;
            _fileContent[2] = "Date Time : " + Global.General.GetUTCDateTime().ToString();
            _fileContent[3] = "Stack Trace :" + Ex.StackTrace.ToString();
            _fileContent[4] = "Target Site : " + Ex.TargetSite.ToString();
            _fileContent[5] = "Location : " + "MyMailManager - " + strLocation;
            _fileContent[6] = "Message : " + Ex.Message;

            WriteExceptionLog("Mail_", _fileContent);
        }

        private static void WriteExceptionLog(string strPrefixFileName, string[] strException)
        {
            try
            {
                CE.InputOut.MyIO _newFile = new CE.InputOut.MyIO();
                string _filePath = AppDomain.CurrentDomain.BaseDirectory + "Exception\\";
                if (_newFile.CheckDirectory(_filePath))
                {
                    string _curMonth = Global.General.GetUTCDateTime().Year.ToString("0000") + Global.General.GetUTCDateTime().Month.ToString("00");

                    if (!_newFile.CheckDirectory(_filePath + _curMonth))
                    {
                        if (_newFile.CreateDirectory(_filePath, _curMonth))
                        {
                            _filePath += _curMonth + "\\";
                        }
                    }
                    else
                    {
                        _filePath += _curMonth + "\\";
                    }

                    string _fileName = strPrefixFileName + _curMonth + Global.General.GetUTCDateTime().Day.ToString("00") + Global.General.GetUTCDateTime().Second.ToString("00") + Global.General.GetUTCDateTime().Millisecond.ToString("00") + ".txt";

                    _newFile.WriteNewFile(_filePath, _fileName, strException);
                    _newFile = null;
                }
            }
            catch (Exception Ex)
            {
                Ex = null;
            }
        }

        private static void CreateMailDeliveryExceptionLog(string strLocation, System.Text.StringBuilder ErrorMessage)
        {
            String[] _fileContent = new String[3];
            _fileContent[0] = "Date Time : " + Global.General.GetUTCDateTime().ToString();
            _fileContent[1] = "Location : " + "MyMailManager - " + strLocation;
            _fileContent[2] = "Message : " + ErrorMessage;

            WriteMailDeliveryExceptionLog("MailDelivery_", _fileContent);
        }

        private static void WriteMailDeliveryExceptionLog(string strPrefixFileName, string[] strException)
        {
            try
            {
                CE.InputOut.MyIO _newFile = new CE.InputOut.MyIO();
                string _filePath = AppDomain.CurrentDomain.BaseDirectory + "Exception\\";
                if (_newFile.CheckDirectory(_filePath))
                {
                    string _curMonth = Global.General.GetUTCDateTime().Year.ToString("0000") + Global.General.GetUTCDateTime().Month.ToString("00");

                    if (!_newFile.CheckDirectory(_filePath + _curMonth))
                    {
                        if (_newFile.CreateDirectory(_filePath, _curMonth))
                        {
                            _filePath += _curMonth + "\\";
                        }
                    }
                    else
                    {
                        _filePath += _curMonth + "\\";
                    }

                    string _fileName = strPrefixFileName + _curMonth + Global.General.GetUTCDateTime().Day.ToString("00") + Global.General.GetUTCDateTime().Second.ToString("00") + Global.General.GetUTCDateTime().Millisecond.ToString("00") + ".txt";

                    _newFile.WriteNewFile(_filePath, _fileName, strException);
                    _newFile = null;
                }
            }
            catch (Exception Ex)
            {
                Ex = null;
            }
        }

        //--CX
        public static bool SendCARMessage(string EmailAddress, string EmailSubject, string EmailMessage)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CarQuotesSMTPSslEnable"));

            string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.CI_CC"].ToString();
            string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.CI_BCC"].ToString();

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname, //"กล้วยๆ.com",
                        noreplysmtpaccount,
                        "Member",
                        EmailAddress,
                        _emailCC,
                        _emailBCC,
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl);
            return _result;
        }

        //Sakthi on 11 Mar 2011 -- Start
        public static bool SendWelcomeMessage(string EmailAddress, string EmailSubject, string EmailMessage)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXWelcomeSMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXWelcomeSMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXWelcomeSMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXWelcomeSMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXWelcomeSMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXWelcomeSMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.CXWelcomeSMTPSslEnable"));

            string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.CXWelcome_CC"].ToString();
            string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.CXWelcome_BCC"].ToString();

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname, //"กล้วยๆ.com",
                        noreplysmtpaccount,
                        "Member",
                        EmailAddress,
                        _emailCC,
                        _emailBCC,
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl);
            return _result;
        }
        //Sakthi on 11 Mar 2011 -- End

        //Sakthi on 29 Jun 2011 -- Start
        public static bool SendCallMeMessage(string EmailAddress, string CCEmailAddress, string BCCEmailAddress, string EmailSubject, string EmailMessage)
        {
            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.NoReplySMTPSslEnable"));

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname, //"กล้วยๆ.com",
                        noreplysmtpaccount,
                        "Member",
                        EmailAddress,
                        CCEmailAddress,
                        BCCEmailAddress,
                        noreplysmtpreplyto,
                        EmailSubject,
                        EmailMessage,
                        noreplysmtpenablessl);
            return _result;
        }
        //Sakthi on 29 Jun 2011 -- End

        public static bool SendMailWithAttach(string CustName, string EmailAddress, string CCEmail, string BCCEmail, string EmailSubject, string EmailMessage, string[] fileList)
        {
            string smtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPHostName");
            string smtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPPort");
            string smtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPAccount");
            string smtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPDisplayName");
            string smtpreplytoemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPReplyTo");
            string smtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPAuthCode");
            bool smtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPSslEnable"));


            string IsLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.IsCXLive");
            if (IsLive == "0" || IsLive == "2")
            {
                EmailSubject = "[TS] " + EmailSubject;
            }

            bool _result = SendGGMailNewByAttachments(smtphost,
                        Convert.ToInt32(smtpport),
                        smtpaccount,
                        smtpauthcode,
                        smtpdisplayname,
                        smtpaccount,
                        CustName,
                        EmailAddress,
                        CCEmail,
                        BCCEmail,
                        smtpreplytoemail,
                        EmailSubject,
                        EmailMessage,
                        smtpenablessl, fileList);
            return _result;
        }

        public static bool SendGGMailNewByAttachments(string sHost, int nPort, string sUserName, string sPassword, string sFromName, string sFromEmail,
        string sToName, string sToEmail, string sCCEmail, string sBCCEmail, string sReplyToEmail, string sHeader, string sMessage, bool fSSL, string[] fileList)
        {
            if (sToName.Length == 0)
                sToName = sToEmail;
            if (sFromName.Length == 0)
                sFromName = sFromEmail;

            MailMessage Mail = new MailMessage();
            try
            {
                if (sToEmail != "")
                {
                    string[] sGetToEmails = sToEmail.Split(';');

                    foreach (string toemail in sGetToEmails)
                    {
                        if (toemail != "")
                            Mail.To.Add(new MailAddress(toemail));
                    }
                }

                if (sCCEmail != "")
                {
                    string[] sGetCCEmails = sCCEmail.Split(';');

                    foreach (string ccemail in sGetCCEmails)
                    {
                        if (ccemail != "")
                            Mail.CC.Add(new MailAddress(ccemail));
                    }
                }

                if (sBCCEmail != "")
                {
                    string[] sGetBCCEmails = sBCCEmail.Split(';');

                    foreach (string bccemail in sGetBCCEmails)
                    {
                        if (bccemail != "")
                            Mail.Bcc.Add(new MailAddress(bccemail));
                    }

                }

                Mail.From = new MailAddress(sFromEmail, sFromName);
                Mail.Subject = sHeader;
                Mail.Body = sMessage;
                Mail.IsBodyHtml = true;
                if (sReplyToEmail != "") Mail.ReplyTo = new MailAddress(sReplyToEmail);

                SmtpClient smtp = new SmtpClient();
                smtp.Port = nPort;
                smtp.Host = sHost;
                smtp.Credentials = new System.Net.NetworkCredential(sUserName, sPassword);

                if (fSSL)
                {
                    smtp.EnableSsl = true;
                }

                object userState = Mail;

                for (int i = 0; i < fileList.Length; i++)
                {
                    Mail.Attachments.Add(new Attachment(fileList[i].ToString()));
                }

                smtp.SendCompleted += new SendCompletedEventHandler(MailDeliveryComplete);
                //smtp.SendAsync(Mail, userState);
                smtp.Send(Mail);


            }
            catch (Exception Ex)
            {
                string _emailSetting = "Host : " + sHost + " From Email : " + sUserName + " To Email : " + sToEmail + " Subject : " + sHeader;
                CreateExceptionLog(Ex, _emailSetting, "SendMailNew By Attachments Exception");

                return false;
            }
            finally
            {
                string MailCountStart = CE.Configuration.MyConfigurationManager.GetAppSettingValue("MailCountStart");
                if (MailCountStart == "1")
                {
                    MailCountLog mcl = new MailCountLog();
                    mcl.InsertMailCountLog("GG Mobile");
                }

                Mail.Dispose();
            }
            return true;
        }

        public static bool SendPasswordResetLink(string UserName, string EmailAddress, string AuthSalt, string UniquiId, CE.Global.General.CEUserType UserType)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "";
            string ConfirmPath = "";
            string userType = "";

            domainUrl = "http://" + myUri.Host;
            userType = "Customer";
            ConfirmPath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.TH.ResetCustomerPasswordPath");


            int portUrl = myUri.Port;
            string confirmUrl = domainUrl + ((portUrl.ToString() == "80") ? "" : ":" + portUrl.ToString());
            string imgUrl = domainUrl;
            confirmUrl += ConfirmPath;

            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.TH.LogoPath");

            string mailBody = "<img src='" + imgUrl + "' width='130' /><br>" + Resources.WelcomeEmail.YourAccount + " : <b>" + UserName + "</b><br>";
            mailBody += "<br><a href='" + confirmUrl + "?authkey=" + AuthSalt + "&uid=" + UniquiId + "'>" + Resources.WelcomeEmail.ClickHere + "</a> " + Resources.WelcomeEmail.ResetAccountPassword;
            mailBody += "<br><br><br>" + Resources.WelcomeEmail.Thankyou;
            mailBody += "<br>" + Resources.WelcomeEmail.BestRegards + ",";
            mailBody += "<br>" + Resources.WelcomeEmail.CompareXpressMembership;

            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPSslEnable"));


            string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.TH.Feedback_CC"].ToString();
            string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.TH.Feedback_BCC"].ToString();

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname, 
                        noreplysmtpaccount,
                        userType,
                        EmailAddress,
                        _emailCC,
                        _emailBCC,
                        noreplysmtpreplyto,
                        "Password Recovery - www.gluaygluay.Com",
                        mailBody,
                        noreplysmtpenablessl);
            return _result;
        }

        public static bool SendChangePassword(string UserName, string EmailAddress, CE.Global.General.CEUserType UserType)
        {
            Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

            string domainUrl = "";
            string userType = "";

            domainUrl = "http://" + myUri.Host;
            userType = "Customer";

            string imgUrl = domainUrl;
            imgUrl += CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.TH.LogoPath");

            string mailBody = "<img src='" + imgUrl + "' width='130' /><br>"; //+ Resources.WelcomeEmail.YourAccount + " : <b>" + UserName + "</b><br>";
            mailBody += "<br>" + Resources.WelcomeEmail.ChangePassword;
            mailBody += "<br><br><br>" + Resources.WelcomeEmail.Thankyou;
            mailBody += "<br>" + Resources.WelcomeEmail.BestRegards + ",";
            mailBody += "<br>" + Resources.WelcomeEmail.CompareXpressMembership;

            string noreplysmtphost = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPHostName");
            string noreplysmtpport = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPPort");
            string noreplysmtpaccount = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPAccount");
            string noreplysmtpdisplayname = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPDisplayName");
            string noreplysmtpreplyto = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPReplyTo");
            string noreplysmtpauthcode = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPAuthCode");
            bool noreplysmtpenablessl = Convert.ToBoolean(CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.InternalSMTPSslEnable"));


            string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.TH.Feedback_CC"].ToString();
            string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["Mobile.TH.Feedback_BCC"].ToString();

            bool _result = SendMailNew(noreplysmtphost,
                        Convert.ToInt32(noreplysmtpport),
                        noreplysmtpaccount,
                        noreplysmtpauthcode,
                        noreplysmtpdisplayname,
                        noreplysmtpaccount,
                        userType,
                        EmailAddress,
                        _emailCC,
                        _emailBCC,
                        noreplysmtpreplyto,
                        Resources.CarInsurance.ChangePasswordCss + " - www.gluaygluay.Com",
                        mailBody,
                        noreplysmtpenablessl);
            return _result;
        }

    }
}